<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="组长头像" prop="avatar">
				<sc-upload
					v-model="form.avatar"
					:apiObj="apiObj"
					title="上传头像"
				></sc-upload>
			</el-form-item>
			<el-form-item label="小组名称" prop="title">
				<el-input v-model="form.title" placeholder="小组名称" maxlength="48" clearable></el-input>
			</el-form-item>
			<el-form-item label="排序号" prop="sortNo">
				<el-input-number v-model="form.sortNo" :min="1" style="width: 100%;"></el-input-number>
			</el-form-item>
			<el-form-item label="小组组长" prop="groupLeader">
				<select-user-dialog v-model:accountId="form.groupLeader" :mode="false"/>
			</el-form-item>
			<el-form-item label="小组成员" prop="member">
				<select-user-dialog v-model:accountId="form.member" :mode="true"/>
			</el-form-item>
			<el-form-item label="是否启用" prop="status">
				<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
			</el-form-item>
			<el-form-item label="备注说明">
				<el-input type="textarea" :rows="2" maxlength="180" placeholder="备注说明" v-model="form.remark"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
import selectUserDialog from "@/views/module/selectUserDialog.vue";

export default {
	components: {
		selectUserDialog
	},
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '创建评标小组',
				edit: '编辑评标小组'
			},
			apiObj:this.$API.file.uploadImg,
			form: {
				avatar:'',
				teamId: "",
				title: "",
				sortNo:"",
				member: "",
				remark: "",
				groupLeader:"",
				status: "1"
			},
			rules: {
				title: [
					{required: true, message: '小组名称'}
				],
				groupLeader: [
					{required: true, message: '小组组长不能为空'}
				],
				member: [
					{required: true, message: '小组成员不能为空'}
				],
				sortNo: [
					{required: true, message: '请输入排序', trigger: 'change'}
				],
			},
			visible: false,
			isSaveing: false,
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					var res;
					if(this.mode=="add")
					{
						this.isSaveing = true;
						res = await this.$API.invite.inviteTeam.insertInviteTeam.post(this.form);
						this.isSaveing = false;
					}else if(this.mode=="edit")
					{
						this.isSaveing = true;
						res = await this.$API.invite.inviteTeam.updateInviteTeam.post(this.form);
						this.isSaveing = false;
					}
					if (res.code == 200) {
						this.$emit('success', this.form, this.mode)
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.teamId = data.teamId
			this.form.title = data.title
			this.form.sortNo = data.sortNo
			this.form.member = data.member
			this.form.remark = data.remark
			this.form.groupLeader = data.groupLeader
			this.form.status = data.status
		}
	}
}
</script>

<style>
</style>
